package com.example.demomk.Adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.demomk.databinding.ItemLocationConutBinding;
import com.example.demomk.entity.LocationStats;

import java.util.ArrayList;
import java.util.List;

public class LocationStatsAdapter extends  RecyclerView.Adapter<LocationStatsAdapter.ViewHolder>{
    private List<LocationStats> data = new ArrayList<>();
    public void submitList(List<LocationStats> list) {
        data = list;
        notifyDataSetChanged();
    }
    @NonNull
    @Override
    public LocationStatsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemLocationConutBinding binding = ItemLocationConutBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull LocationStatsAdapter.ViewHolder holder, int position) {
        LocationStats item = data.get(position);
        holder.locName.setText(item.getLocationName());
        holder.locCount.setText(String.valueOf(item.getCount()));
        holder.locZero.setText(String.valueOf(item.getAvg05()));
        holder.locOne.setText(String.valueOf(item.getAvg10()));
        holder.locTwo.setText(String.valueOf(item.getAvg20()));
        holder.locThere.setText(String.valueOf(item.getAvg30()));
        holder.locFive.setText(String.valueOf(item.getAvg50()));
        holder.locTen.setText(String.valueOf(item.getAvg100()));
    }

    @Override
    public int getItemCount() {
        return data.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView locName, locCount, locZero, locOne, locTwo, locThere, locFive, locTen;
        public ViewHolder(@NonNull ItemLocationConutBinding binding) {
            super(binding.getRoot());
            locName = binding.locName;
            locCount = binding.locCount;
            locZero = binding.LocZeroFive;
            locOne = binding.LocOne;
            locTwo = binding.LocTwo;
            locThere = binding.LocThree;
            locFive = binding.LocFive;
            locTen = binding.LocTen;
        }
    }
}
